package com.lekang.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.system.domain.BillDetail;
import com.lekang.system.service.IBillDetailService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 账单详情Controller
 * 
 * @author lekang
 * @date 2025-10-24
 */
@RestController
@RequestMapping("/system/billDetail")
public class BillDetailController extends BaseController
{
    @Autowired
    private IBillDetailService billDetailService;

    /**
     * 查询账单详情列表
     */
//    @PreAuthorize("@ss.hasPermi('system:billDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(BillDetail billDetail)
    {
        startPage();
        List<BillDetail> list = billDetailService.selectBillDetailList(billDetail);
        return getDataTable(list);
    }

    /**
     * 根据账单ID查询账单详情列表（不分页）
     */
//    @PreAuthorize("@ss.hasPermi('system:billDetail:list')")
    @GetMapping("/listByBillId/{billId}")
    public AjaxResult listByBillId(@PathVariable("billId") Long billId)
    {
        List<BillDetail> list = billDetailService.selectBillDetailListByBillId(billId);
        return success(list);
    }

    /**
     * 导出账单详情列表
     */
//    @PreAuthorize("@ss.hasPermi('system:billDetail:export')")
//    @Log(title = "账单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillDetail billDetail)
    {
        List<BillDetail> list = billDetailService.selectBillDetailList(billDetail);
        ExcelUtil<BillDetail> util = new ExcelUtil<BillDetail>(BillDetail.class);
        util.exportExcel(response, list, "账单详情数据");
    }

    /**
     * 获取账单详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:billDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(billDetailService.selectBillDetailById(id));
    }

    /**
     * 新增账单详情
     */
//    @PreAuthorize("@ss.hasPermi('system:billDetail:add')")
//    @Log(title = "账单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BillDetail billDetail)
    {
        return toAjax(billDetailService.insertBillDetail(billDetail));
    }

    /**
     * 修改账单详情
     */
//    @PreAuthorize("@ss.hasPermi('system:billDetail:edit')")
//    @Log(title = "账单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BillDetail billDetail)
    {
        return toAjax(billDetailService.updateBillDetail(billDetail));
    }

    /**
     * 删除账单详情
     */
//    @PreAuthorize("@ss.hasPermi('system:billDetail:remove')")
//    @Log(title = "账单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(billDetailService.deleteBillDetailByIds(ids));
    }
}


